package org.aphelie.chronicle;

import java.lang.reflect.Field;

import org.eclipse.osgi.util.NLS;

public abstract class ArcMessages extends NLS {

	public ArcMessages() {
	}
	
	public String getMessage(ArcElement element, ArcMessageFormat format) {
		String id = element.getId();
		if (id == null) {
			id = element.eClass().getName();
		}
		return getString(format.getKey(id));
	}

	public String getString(String fieldName) {
		String value = String.format("!%s!", fieldName);
		try {
			Field field = this.getClass().getField(fieldName);
			String objectInstance = new String();
			value = field.get(objectInstance).toString();
		} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		} 
		return value;
	}

}
